﻿<%@ WebHandler Language="C#" Class="blackListManage" %>

using System;
using System.Web;
using System.Text;
using System.Collections.Generic;
using Chenxin.Lib.Utility;

public class blackListManage  : AjaxHandlerBase
{

    //*******************************************
    //功能概要       ：重写的请求处理方法
    //参数説明       ：context 请求的上下文
    //返回值説明     ：无
    //功能詳細       ：父类中隐藏了IHttpHandler接口方法，本类中须对本方法进行重写
    //作成者         ：he.jifeng 
    //作成日         ：2010-03-29 
    //*******************************************
    override public void RequestProcess(HttpContext context)
    {
        context.Response.AddHeader("pragma", "no-cache");
        context.Response.AddHeader("cache-control", "");
        context.Response.CacheControl = "no-cache";
        
        //处理类型
        string strDealType  = context.Request.Params["op"];

        switch (strDealType)
        {
            case "GetCondition":
                getCondition(context);
                break;
            case "GetSingle":
                getSingleBlackList(context);
                break;
            case "Search":
                searchBlackList(context);
                break;
            case "Save":
                saveBlackList(context);
                break;
            case "Del":
                delBlackList(context);
                break;
        }
    }

    //*******************************************
    //功能概要       ：匹配条件
    //参数説明       ：context 请求上下文
    //返回值説明     ：无
    //功能詳細       ：匹配条件
    //作成者         ：he.jifeng 
    //作成日         ：2010-03-29
    //*******************************************
    public void getCondition(HttpContext context)
    {
        StringBuilder strHtml = new StringBuilder();

        string strQuery = context.Request.Params["Query"];
        
        try
        {
            //黑名单业务类
            Chenxin.Lib.Hr.BLL.Hr_BlackList bllBlackList = new Chenxin.Lib.Hr.BLL.Hr_BlackList();
            //黑名单实体类
            List<Chenxin.Lib.Hr.Entity.Hr_BlackList> lsBlackList = bllBlackList.GetListByQuery(strQuery);

            if (lsBlackList.Count > 0)
            {
                strHtml.Append("<dt>黑名单用户名</dt>");

                for (int idxCnt = 0; idxCnt < lsBlackList.Count; idxCnt++)
                {
                    strHtml.Append("<dd>");
                    strHtml.Append(" <input type=hidden name='hidType' value='UserName' />");
                    strHtml.Append(" <input type=hidden name='hidCont' value='" + lsBlackList[idxCnt].UserName + "' />");
                    strHtml.Append(" <a class='clsAUser' href='#'>" + lsBlackList[idxCnt].UserName + "</a>");
                    strHtml.Append("</dd>");
                }
            }

            context.Response.Write(retExecResult(Constants.ExecResult.Succ, "OK", strHtml.ToString()));
        }
        catch (Exception ex)
        {
            //错误信息回传
            context.Response.Write(retExecResult(Constants.ExecResult.Error, ex.Message, ""));
        }
    }

    //*******************************************
    //功能概要       ：根据条件查找黑名单列表
    //参数説明       ：context 请求上下文
    //返回值説明     ：无
    //功能詳細       ：根据条件查找黑名单列表
    //作成者         ：he.jifeng 
    //作成日         ：2010-03-29
    //*******************************************
    public void searchBlackList(HttpContext context)
    {
        string strRet;
        int CntOfTotal;
        Constants.Pagination stuPg = new Constants.Pagination();
        
        StringBuilder strHtml = new StringBuilder();
        System.Collections.Hashtable hsParams = new System.Collections.Hashtable();
        
        string strType;
        string strCont;
        string strParam;
        string strLevel;
        
        strCont = context.Request.Params["CondCont"];
        strParam = context.Request.Params["Level"];
        
        if (strParam != null)
        {
            hsParams.Add("Level", strParam);
        }
        //首字母
        strParam = context.Request.Params["Initial"];
        if (strParam != null)
        {
            hsParams.Add("Initial", strParam);
        }
        //查询数据类型
        if (!string.IsNullOrEmpty(strCont))
        {
            hsParams.Add("UserName", strCont);
        }
        //当前页数
        strParam = context.Request.Params["pageindex"];
        if ( !string.IsNullOrEmpty(strParam))
        {
            hsParams.Add("pageIndex", (int.Parse(strParam) + 1).ToString());
        }
        //总页数
        strParam = context.Request.Params["pagesize"];
        if ( !string.IsNullOrEmpty(strParam))
        {
            hsParams.Add("pageSize", strParam);
        }
        
        //黑名单业务类
        Chenxin.Lib.Hr.BLL.Hr_BlackList bllBlackList = new Chenxin.Lib.Hr.BLL.Hr_BlackList();
        //黑名单实体类
        List<Chenxin.Lib.Hr.Entity.Hr_BlackList> lsBlackList = bllBlackList.GetListByCondition(hsParams, out CntOfTotal);
        
        try
        {
            for (int idxCnt = 0; idxCnt < lsBlackList.Count; idxCnt++)
            {
                strLevel = lsBlackList[idxCnt].Level.ToString();
                switch (strLevel)
                {
                    case"10":
                        strLevel = "公司级";
                        break;
                    case "20":
                        strLevel = "部门级";
                        break;
                    case "30":
                        strLevel = "个人级";
                        break;
                }

                strHtml.Append("<div class='outshadow fl'>");
                strHtml.Append("    <div class='conpsonbox'>");
                strHtml.Append("        <h1>");
                strHtml.Append("            <span class='fl'>" + lsBlackList[idxCnt].UserName + "</span>");
                strHtml.Append("            <a href='#' class='fr bluelink clsEditBlackList'>编辑</a>");
                strHtml.Append("            <a href='#' class='fr bluelink clsDelBlackList'>删除</a>");
                strHtml.Append("            <input name='hidRecordId' type=hidden value=" + lsBlackList[idxCnt].RecordId.ToString() + " />");
                strHtml.Append("        </h1>");
                strHtml.Append("        <p>姓名：" + lsBlackList[idxCnt].UserName + "</p>");
                strHtml.Append("        <p>手机：" + lsBlackList[idxCnt].Mobile + "</p>");
                strHtml.Append("        <p>电话：" + lsBlackList[idxCnt].Tel + "</p>");
                strHtml.Append("        <p>邮箱：" + lsBlackList[idxCnt].Email + "</p>");
                strHtml.Append("        <p>地址：" + lsBlackList[idxCnt].Address + "</p>");
                strHtml.Append("        <p>类别：" + strLevel + "</p>");
                strHtml.Append("    </div>");
                strHtml.Append("</div>");
            }

            stuPg.count = CntOfTotal;//总计多少数据
            stuPg.data = strHtml.ToString();
            strRet = retExecResult(Constants.ExecResult.Succ, "OK", stuPg);
            context.Response.Write(strRet);   
        }
        catch (Exception ex)
        {
            //错误信息回传
            strRet = retExecResult(Constants.ExecResult.Error, ex.Message, "");
            context.Response.Write(strRet);
        }
    }

    //*******************************************
    //功能概要       ：保存黑名单人员
    //参数説明       ：context 请求上下文
    //返回值説明     ：无
    //功能詳細       ：保存黑名单人员
    //作成者         ：he.jifeng 
    //作成日         ：2010-04-16
    //*******************************************
    public void saveBlackList(HttpContext context)
    {
        string strRet;
        string strMsg;
        try
        {
            //黑名单业务类
            Chenxin.Lib.Hr.BLL.Hr_BlackList bllBlackList = new Chenxin.Lib.Hr.BLL.Hr_BlackList();
            
            //实体类
            Chenxin.Lib.Hr.Entity.Hr_BlackList entBlackList =
            (Chenxin.Lib.Hr.Entity.Hr_BlackList)Chenxin.Lib.Utility.JsonHelp.Convert2Entity(context.Request["model"], typeof(Chenxin.Lib.Hr.Entity.Hr_BlackList));

            entBlackList.Initial = InitialHelper.getInitial(entBlackList.UserName.Substring(0, 1));
            
            entBlackList.AddUser = CurrentUserInfo.UserName;
            entBlackList.AddDepart = CurrentUserInfo.DepartName;
            entBlackList.AddCompany = CurrentUserInfo.CompanyName;
            entBlackList.UpdateTime = DateTime.Now;
            
            if (Guid.Empty.Equals(entBlackList.RecordId))
            {
                entBlackList.RecordId = Guid.NewGuid();
                bllBlackList.Add(entBlackList);
                
                //添加用户操作日志 2010-5-12 王玮 Add
                AddLog("" + CurrentUserInfo.UserName + "添加了一个黑名单:姓名[" + entBlackList.UserName + "]",
                        OperationType.OperationTypeComboList()["OprType_BlackListAdd"].ToString()); 
                 
                strMsg = "添加成功";
            }
            else
            {
                bllBlackList.Update(entBlackList);

                //添加用户操作日志 2010-5-12 王玮 Add
                AddLog("" + CurrentUserInfo.UserName + "编辑了一个黑名单:姓名[" + entBlackList.UserName + "]",
                        OperationType.OperationTypeComboList()["OprType_BlackListEdit"].ToString()); 
                
                strMsg = "更新成功";
            }

            strRet = retExecResult(Constants.ExecResult.Succ, strMsg, "");
            context.Response.Write(strRet);
        }
        catch (Exception ex)
        {
            strRet = retExecResult(Constants.ExecResult.Error, ex.Message, "");
            context.Response.Write(strRet);
        }
    }
    
    //*******************************************
    //功能概要       ：取得黑名单账户
    //参数説明       ：context 请求上下文
    //返回值説明     ：无
    //功能詳細       ：取得黑名单账户
    //作成者         ：he.jifeng 
    //作成日         ：2010-03-29
    //*******************************************
    private void getSingleBlackList(HttpContext context)
    {
        try
        {
            string strRecordId = context.Request.Params["RecordId"];
            //黑名单业务类
            Chenxin.Lib.Hr.BLL.Hr_BlackList bllBlackList = new Chenxin.Lib.Hr.BLL.Hr_BlackList();
            //黑名单实体类
            Chenxin.Lib.Hr.Entity.Hr_BlackList entBlackList = bllBlackList.GetModel(new Guid(strRecordId));
            
            //响应内容
            context.Response.Write(retExecResult(Constants.ExecResult.Succ, "OK", entBlackList));
        }
        catch (Exception ex)
        {
            //错误信息回传
            context.Response.Write(retExecResult(Constants.ExecResult.Error, ex.Message, ""));
        }   
    }
    //*******************************************
    //功能概要       ：删除黑名单账户
    //参数説明       ：context 请求上下文
    //返回值説明     ：无
    //功能詳細       ：删除黑名单账户
    //作成者         ：he.jifeng 
    //作成日         ：2010-03-29
    //*******************************************
    private void delBlackList(HttpContext context)
    {
        try
        {
            string strRecordId = context.Request.Params["RecordId"];
            //黑名单业务类
            Chenxin.Lib.Hr.BLL.Hr_BlackList bllBlackList = new Chenxin.Lib.Hr.BLL.Hr_BlackList();
            //获取黑名单实体
            Chenxin.Lib.Hr.Entity.Hr_BlackList clhehbl = Chenxin.Lib.Hr.DAL.Hr_BlackList.GetModel(new Guid(strRecordId));
            //删除黑名单账户
            bllBlackList.Delete(new Guid(strRecordId));
            //添加用户操作日志 2010-5-12 王玮 Add
            AddLog("" + CurrentUserInfo.UserName + "删除了一个黑名单:姓名[" + clhehbl.UserName + "]",
                    OperationType.OperationTypeComboList()["OprType_BlackListDel"].ToString()); 
            //响应内容
            context.Response.Write(retExecResult(Constants.ExecResult.Succ, "删除成功！", ""));
        }
        catch (Exception ex)
        {
            //错误信息回传
            context.Response.Write(retExecResult(Constants.ExecResult.Error, ex.Message, ""));
        }
    }
}